package targetToOffer.fifthDay;




/**
 * @author Godc
 * @description
 */
public class IsSymmetric {
}
class IsSymmetricSolution {
    public boolean isSymmetric(TreeNode root) {
        if(root==null) return true;
        return check(root,root);
    }

    public boolean check(TreeNode a, TreeNode b){
        if(a==null&&b==null) return true;
        // 深度都不相同，肯定不是镜像
        if(a==null||b==null) return false;
        boolean f1 = check(a.left, b.right);
        boolean f2 = check(a.right, b.left);
        return ((a.val==b.val)&&f1&&f2);
    }
    /**
     * 精简版
     * @param a
     * @param b
     * @return
     */
    public boolean check1(TreeNode a, TreeNode b){
        if(a==null&&b==null) return true;
        if(a==null||b==null||(a.val!=b.val)) return false;
        return check1(a.left,b.right)&&check1(a.right,b.left);
    }
}

